package com.blue.bluecode;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public class RadioButtonActivity extends Activity {

    private RadioGroup rgRadioGroup;
    private RadioButton rbMale,rbFemale,rbNoPeople;
    private TextView tvChoose;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_button);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        initView();



    }

    private void initView() {
        rgRadioGroup = (RadioGroup) findViewById(R.id.rgRadioGroup);

        rbMale = (RadioButton) findViewById(R.id.rbMale);
        rbFemale = (RadioButton) findViewById(R.id.rbFemale);
        rbNoPeople = (RadioButton) findViewById(R.id.rbNoPeople);
        tvChoose = (TextView) findViewById(R.id.tvChoose);

        rgRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            /**
             * 当RadioButton选择改变的时候
             * @param radioGroup RadioGroup
             * @param i checkedId被选中的RadioButton的ID
             */
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton rb = (RadioButton) RadioButtonActivity.this.findViewById(i);
                tvChoose.setText("你选择的是:" + rb.getText());
            }
        });

    }

}
